﻿using System;
using Framework.MVC;
using Identity.Model;
using Account.Model;
using Account.Model.Behavior;
using Framework.MVVM.Model;
using Identity.IService;
using Identity.Service;
using Account.IService;
using Account.Service;

namespace FrontCenter.Models
{
    [ServiceAttribute(typeof(IAnswerService), typeof(AnswerService), "Instance")]
    [ServiceAttribute(typeof(IIdentityService), typeof(IdentityService), "Instance")]
    public class ContainsAnswerModel : AsyncModelBase, IValidateIdentity, IContainsAnswers
    {
        #region Field

        private const string m_resource_user = "u000";

        private const string m_user = "user";
        private const string m_status = "error";

        #endregion Field

        #region AsyncModelBase

        protected override void OnInit(Type type)
        {
            this.OnBeginRequest();
            this.ValidateIdentity(m_resource_user,string.Empty,string.Empty,string.Empty);
        }

        #endregion AsyncModelBase

        #region IValidateIdentity

        public string IdentityCode { get; set; }

        public bool IsOnce { get; set; }

        public string Source { get; set; }
        
        public void OnValidateIdentityComplete(string key, Identity.IService.Entry.IdentityEntry entry)
        {
            AccountCode = entry.value;
            this.ContainsAnswers(m_user,string.Empty,string.Empty);
        }

        public void OnValidateIdentityError(string key)
        {
            OnComplete(m_status, "identity");
            this.OnEndRequest();
        }

        #endregion IValidateIdentity

        #region IContainsAnswers

        public string AccountCode { get; set; }

        public void OnContainsAnswersComplete(string key, bool entry)
        {
            OnComplete(m_status, "contains");
            this.OnEndRequest();
        }

        public void OnContainsAnswersError(string key)
        {
            this.OnEndRequest();
        }

        #endregion IContainsAnswers
    }
}